﻿Imports Entities
Public Class FacturaDAl
    Public Shared Function Create(ByVal zObject As FACTURAS) As FACTURAS
        Try
            Using bd As New gas_gasdesuvecinoEntities
                bd.FACTURAS.Add(zObject)
                bd.SaveChanges()
                Return zObject
            End Using
        Catch ex As Exception
            Debug.Print("FacturaDAL.Create() " + ex.Message)
            Return Nothing
        End Try
    End Function
    Public Shared Function List() As List(Of FACTURAS)
        Using bd As New gas_gasdesuvecinoEntities
            Return bd.FACTURAS.ToList
        End Using
    End Function
    Public Shared Function Existe(ByVal zId As Long) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.FACTURAS
                            Where rec.FACTURA = zId
                            Select rec).Count
                If query > 0 Then
                    Return True
                Else
                    Return False
                End If
            End Using
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function CheckPedido(ByVal zPedidoId As Long) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.FACTURAS
                            Where rec.PEDIDO = zPedidoId
                            Select rec).Count
                If query > 0 Then
                    Return True
                Else
                    Return False
                End If
            End Using
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function SearchById(ByVal zId As Integer) As FACTURAS
        Using bd As New gas_gasdesuvecinoEntities
            Return bd.FACTURAS.Find(zId)
        End Using
    End Function
End Class
